package net.googlecode.demenkov.services.impl;

import net.googlecode.demenkov.dao.FriendshipDAO;
import net.googlecode.demenkov.domains.Friendship;
import net.googlecode.demenkov.domains.Person;
import net.googlecode.demenkov.services.FriendshipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Service-class for actions with friendships
 *
 * @author Demenkov Yura
 */
@Service
public class FriendshipServiceImpl implements FriendshipService {
    @Autowired
    private FriendshipDAO friendshipDAO;

    @Transactional
    public void createFriendship(Friendship friendship) {
        friendshipDAO.create(friendship);
    }

    @Transactional
    public void confirmFriendship(Friendship friendship) {
        friendship.setConfirmed(true);
        friendshipDAO.update(friendship);
    }

    @Transactional
    public void deleteFriendship(Friendship friendship) {
        friendshipDAO.delete(friendship);
    }

    @Transactional
    public Friendship findFriendshipByPersons(Person personWhoSend, Person personWhoGet) {
        return friendshipDAO.findFriendshipByPersons(personWhoSend, personWhoGet);
    }
}
